package com.zijie;

import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Q3 {

    //可以复制到idea看看



    private static final int[][] DIRECTIONS = {
            {-1, 0}, {1, 0}, {0, -1}, {0, 1}
    };

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int k = scanner.nextInt();

        int[][] maze = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                maze[i][j] = scanner.nextInt();
            }
        }

        int x1 = scanner.nextInt() - 1;//1
        int y1 = scanner.nextInt() - 1;//2
        int x2 = scanner.nextInt() - 1;//3
        int y2 = scanner.nextInt() - 1;//4
        int ex = scanner.nextInt() - 1;//5
        int ey = scanner.nextInt() - 1;//6

        int time1 = findShortestTime(maze, n, m, k, x1, y1, ex, ey);
        int time2 = findShortestTime(maze, n, m, k, x2, y2, ex, ey);
        System.out.println(time1 + " " + time2);
    }

    private static int findShortestTime(int[][] maze, int n, int m, int k,
                                        int startX, int startY, int endX, int endY) {
        PriorityQueue<int[]> queue = new PriorityQueue<>(
                Comparator.comparingInt(a -> a[2]));
        int[][] dist = new int[n][m];

        for (int i = 0; i < n; i++) {
            Arrays.fill(dist[i], Integer.MAX_VALUE);
        }

        dist[startX][startY] = 0;
        queue.offer(new int[]{startX, startY, 0});

        while (!queue.isEmpty()) {
            int[] current = queue.poll();
            int x = current[0];
            int y = current[1];
            int time = current[2];

            if (x == endX && y == endY) {
                return time;
            }

            if (time > dist[x][y]) {
                continue;
            }
            for (int[] dir : DIRECTIONS) {

                int nx = x + dir[0];
                int ny = y + dir[1];

                if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
                    int cost=0;
                    int diff=Math.abs(maze[x][y]-maze[nx][ny]);

                    if(diff>k) {
                        cost=6;
                    }

                    int newTime = time+cost;

                    if(newTime<dist[nx][ny]) {
                        dist[nx][ny]=newTime;
                        queue.offer(new int[]{nx,ny,newTime});
                    }
                }
            }
        }
        return dist[endX][endY];
    }
}
